package img;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class Fra {

    public static void main(String[] args) {
        JFrame frame = new JFrame("AAA");
        // Toolkit tool = frame.getToolkit(); // 得到一个Toolkit对象
        // Image myimage = tool.getImage("src/img/panda.png"); // 由tool获取图像
        // frame.setIconImage(myimage);

        File file = new File("src/img/panda.png");
        System.out.println(file.getAbsolutePath());
        System.out.println(file.exists());
        // System.out.println(file.getAbsolutePath());
        ImageIcon imageIcon = new ImageIcon(file.getAbsolutePath());
        frame.setIconImage(imageIcon.getImage());
        /**
         * 设置屏幕居中
         */
        // 获取屏幕大小
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setSize(screenSize.width / 3 * 2, screenSize.height / 3 * 2);
        // 让窗口居中显示
        frame.setLocation(screenSize.width / 2 - screenSize.width / 3, screenSize.height / 2 - screenSize.height / 3);

        frame.setVisible(true);
        // 不能使用，会导致尺寸自动变化
        // frame.pack();
        // frame.show();
        }

}
